package com.shangcheng.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangcheng.dubbo.mappers.SmsCouponHistoryMapper;
import com.shangcheng.model.domain.SmsCouponHistory;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 */
@DubboService
public class SmsCouponHistoryApiImpl implements SmsCouponHistoryApi {

    @Autowired
    private SmsCouponHistoryMapper smsCouponHistoryMapper;

    /**
     * 查看优惠券历史
     *
     * @param couponId
     * @param orderSn
     * @param pageNum
     * @param pageSize
     * @param useStatus
     * @return
     */
    @Override
    public IPage list(Integer couponId, String orderSn,
                      Integer pageNum, Integer pageSize,
                      Integer useStatus) {
        //1.设置page参数
        IPage page = new Page(pageNum, pageSize);
        //2.设置keyword参数查询条件
        LambdaQueryWrapper<SmsCouponHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(couponId != null, SmsCouponHistory::getCouponId, couponId);
        wrapper.eq(StringUtils.isNotBlank(orderSn), SmsCouponHistory::getOrderSn, orderSn);
        wrapper.eq(useStatus != null, SmsCouponHistory::getUseStatus, useStatus);
        return smsCouponHistoryMapper.selectPage(page, wrapper);
    }
}
